# util.tcl - utility functions. used for cleaning up code.

# CONTENTS:
#	getchid
#		Goes through some variables and returns the current
#		chid associated with a server tab. Takes no arguments
#
#	getchan ?channel?
#		Goes through some variables and returns the current
#		channel frame widget active. Takes no arguments.
#	
#	chanjoin channel
#		Makes T2I join a channel
#
#	chanpart channel
#		Makes T2I part a channel

proc getchid {} {
	global n_conns conns
	
	set server [$n_conns tab [$n_conns select] -text]
	return $conns($server)
}

proc getchan {{channel {}}} {
	global n_conns conns
	
	set chid [getchid]
	global CHANS_$chid
	set currservertab $n_conns.$chid
	
	if {"$channel" == {}} {
		set channel [$currservertab tab [$currservertab select] -text]
	}
	
	set view $currservertab.console
	if { $channel != [tr Console] } {
		set num [set "CHANS_$chid\([string tolower $channel]\)"]
		set view $currservertab.chan$num
	}
	
	return $view
}

# Channel action utils
proc chanjoin {channel} { raw [getchid] "JOIN $channel"; }
proc chanpart {channel} { raw [getchid] "PART $channel"; }
